<template>
    <view class="view-item-image-head-attention" @click="attentionFn">关注</view>
</template>
    
<script setup>

import { reactive, ref, getCurrentInstance, onMounted } from "vue"

import { onLoad } from '@dcloudio/uni-app'
import { showToast } from 'vant';
import {
    FollowUser
} from "@/api/im/index.js"

let { proxy } = getCurrentInstance()

const state = reactive({
    show: false,
    actions: [
        { name: '删除' },
        { name: '仅自己可见' },
    ],
    followUserID: ""
})

const squareFn = () => {
    state.show = true
}

const props = defineProps({
    _color: {
        type: String,
        default: "#333"
    },
    followUserID:{
        type: [String,Number],
        default: null
    }
})

const emits = defineEmits(["update:isFollowUpdate"])

const attentionFn = async () => {
    let params = {
        "followUserID": props.followUserID ? props.followUserID : state.followUserID,
        "pagePatch": "动态详情"
    }
    try {
        let data = await proxy.$post(FollowUser, params)
        if (data.code == 200) {
            showToast("关注成功")
            emits("update:isFollowUpdate",true)
        }
    } catch (error) {
        showToast("关注失败")
    }

}

onLoad((options) => {
    state.followUserID = options.id ? options.id : options.userId
})

</script>
    
<style lang="scss" scoped >
.view-item-image-head-attention {
    border: 1px solid #333;
    padding: 5rpx 30rpx;
    border-radius: 150rpx;
    margin-right: 20rpx;
}
</style>
    